package com.css.fxfzaqbz.modules.data.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.DisposeSubtitle;
import com.css.fxfzaqbz.modules.data.service.DisposeSubtitleService;
import com.css.fxfzaqbz.modules.supergraph.exception.CustomException;
import com.css.fxfzaqbz.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class DisposeSubtitleController {
    @Resource
    private DisposeSubtitleService disposeSubtitleService;

    /**
     * 保存新的标签
     *
     * @param disposeSubtitle 处置分析的标签信息
     * @return 处理结果
     */
    @PostMapping("/saveDisposeSubtitle")
    public RestResponse saveDisposeSubtitle(@RequestBody DisposeSubtitle disposeSubtitle) {
        RestResponse restResponse = null;
        try {
            disposeSubtitleService.saveDisposeSubtitle(disposeSubtitle);
            restResponse = RestResponse.succeed();
        } catch (CustomException e) {
            log.error("新增处置分析子标签失败", e);
            restResponse = RestResponse.fail(e.getMessage());
        } catch (Exception e) {
            log.error("新增处置分析子标签失败", e);
            restResponse = RestResponse.fail("新增处置分析子标签失败!");
        }
        return restResponse;
    }


    /**
     * 根据 id 删除标签
     *
     * @param ids 标签id
     * @return
     */
    @PostMapping("/delDisposeSubtitle/{ids}")
    public RestResponse delDisposeSubtitle(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            disposeSubtitleService.delDisposeSubtitle(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除处置分析子标签失败!", e);
            restResponse = RestResponse.fail("删除处置分析子标签失败!");
        }
        return restResponse;
    }




    @GetMapping("/getDisposeAllSubtitle")
    public RestResponse getDisposeAllSubtitle(HttpServletRequest request,DisposeSubtitle disposeSubtitle) {
        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            restResponse = RestResponse.succeed(disposeSubtitleService.getDisposeAllSubtitle(curPage,pageSize,disposeSubtitle));
        } catch (Exception e) {
            log.error("获取处置分析子标签失败!", e);
            restResponse = RestResponse.fail("获取处置分析子标签失败!");
        }
        return restResponse;
    }


}
